package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysCompany;
import com.ruoyi.system.domain.SysProduct;
import com.ruoyi.system.service.ISysCompanyService;
import com.ruoyi.web.service.MpCompanyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/system/company")
public class SysCompanyController extends BaseController {


    @Autowired
    private MpCompanyService companyService;

    @ApiModelProperty(value = "门店列表信息")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(value = "keyword", required = false) String keyword,
                              @RequestParam(value = "pageNum", defaultValue = "1") Integer page,
                              @RequestParam(value = "pageSize", defaultValue = "10") Integer limit) {
        return companyService.getList(keyword,page,limit);
    }


    @PreAuthorize("@ss.hasPermi('system:company:add')")
    @Log(title = "企业管理", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@Validated @RequestBody SysCompany company)
    {
        return AjaxResult.success(companyService.save(company));
    }

    @PreAuthorize("@ss.hasPermi('system:company:update')")
    @Log(title = "企业修改", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update")
    public AjaxResult update(@RequestBody SysCompany company)
    {
        return AjaxResult.success(companyService.update(company));
    }


    @PreAuthorize("@ss.hasPermi('system:company:delete')")
    @Log(title = "企业删除", businessType = BusinessType.DELETE)
    @PostMapping(value = "/delete")
    public AjaxResult delete(@RequestBody SysCompany company)
    {
        return AjaxResult.success(companyService.delete(company));
    }

    @ApiModelProperty(value = "门店关键字搜索下拉框")
    @GetMapping("/select")
    public List<SysCompany> select(@RequestParam(value = "keyword") String keyword) {
        return companyService.selectList(keyword);
    }

}
